<?php

class PhpFox_Mod_Video_ComponentFavorites extends BaseComponent
{
    function process()
    {
    	if ( !App::checkUserAccess('video', array('full', 'read_only'), false) )
		{
			return '';
		}

    	$oReq = &App::getRequest();
    	$sUser = $this->getParam('user');

		if ( $iDelete = $oReq->get('deletevideo') )
		{
			$this->oDatabase->query("DELETE FROM ". App::getT('videos_favorite') ."
				WHERE id = '". $iDelete ."' AND user_id = '". App::getUser('id') ."'");
		}

    	if ( $sUser == 'current' )
    	{
			$aItems = $this->oDatabase->getRows("SELECT v.vid_id, v.vid_title, f.user_id, f.id FROM
				". App::getT('videos_favorite') ." AS f,
				". App::getT('videos') ." AS v
				WHERE f.video_id = v.vid_id AND f.user_id = '". App::getUser('id') ."'
				ORDER BY v.vid_time DESC");
    	}
    	else
    	{
			$aItems = $this->oDatabase->getRows("SELECT v.vid_id, v.vid_title, f.user_id, f.id FROM
				". App::getT('videos_favorite') ." AS f,
				". App::getT('videos') ." AS v
				WHERE f.video_id = v.vid_id AND f.user_id = '". $sUser->aData['id'] ."'
				ORDER BY v.vid_time DESC");
    	}

		$this->oTpl->assign(array
		(
			'sGImageUrl' => App::getParam('video.image.url'),
			'aItems' => $aItems,
			'bDisplayDelete' => true,
		));

		return $this->oTpl->fetch('Favorites.html');
    }
}

?>